package cn.js.sangu.unitStore.mapper;

import cn.js.sangu.unitStore.dto.LogOperationDTO;
import cn.js.sangu.unitStore.dto.LogSummaryDTO;
import cn.js.sangu.unitStore.entity.Charts;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 拥有MP框架的方法
 */
@Mapper
public interface ChartsMapper extends BaseMapper<Charts> {

    @Select("SELECT date(opera_time) as log_date, uid, count(*) as num FROM logs " +
            "WHERE opera_time >= CURDATE() - INTERVAL 7 DAY " +
            "GROUP BY date(opera_time), uid " +
            "ORDER BY id DESC")
    List<LogSummaryDTO> getLogSummaryLast7Days();

    @Select("SELECT date(opera_time) as log_date, count(*) as num FROM logs " +
            "WHERE uid = #{uid} and opera_time >= CURDATE() - INTERVAL 7 DAY " +
            "GROUP BY date(opera_time) " +
            "ORDER BY id DESC")
    List<LogSummaryDTO> getLogSummaryLast7DaysByUid(Integer uid);

    @Select("SELECT date(opera_time) as log_date, count(*) as num FROM logs " +
            "WHERE opera_time >= CURDATE() - INTERVAL 7 DAY " +
            "GROUP BY date(opera_time) " +
            "ORDER BY id DESC")
    List<LogSummaryDTO> getLogSummaryLast7DaysByAllUser();

    @Select("SELECT operation, count(*) as num FROM logs " +
            "WHERE opera_time >= CURDATE() - INTERVAL 7 DAY " +
            "GROUP BY operation " +
            "ORDER BY id DESC")
    List<LogOperationDTO> getLogOperationLast7DaysByAllUser();

}
